package com.huobao.yunying.adapters;

import java.util.Map;

import org.simple.eventbus.EventBus;

import com.huobao.yunying.activitys.muyingquan.SheQuHuiTie;
import com.huobao.yunying.activitys.muyingquan.SheQu_ShouCang;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;
import com.xrz.sxm.base.dialog.BaseDialog;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

public class Adapter_SheQu_HuiTie extends QuickAdapter<SheQuHuiTie>{

	public Adapter_SheQu_HuiTie(Context context) {
		super(context, R.layout.item_shequ_huitie);
	}

	@Override
	protected void convert(BaseAdapterHelper arg0, final SheQuHuiTie arg1) {
		TextView tv_huitie_content=arg0.getView(R.id.tv_huitie_content);
		TextView tv_yuantie=arg0.getView(R.id.tv_yuantie);
		TextView tv_del=arg0.getView(R.id.del_huitie);
		TextView tv_time=arg0.getView(R.id.tv_huitie_time);
		tv_huitie_content.setText(arg1.getComment());
		tv_yuantie.setText(arg1.getTitle());
		tv_time.setText(arg1.getDateline());
		tv_del.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				BaseDialog.TBox("确定删除吗？", context, new BaseDialog.OnDialogSelectListener() {
					@Override
					public void onSelect(String input) {
						if (input.equals("true"))
							del(arg1);
					}
				});

			}
		});
		
	}

	protected void del(final SheQuHuiTie arg1) {
		Map<String, String> map = HttpUtil.getParams("app","postcomment","act","drop","id",arg1.getCid());
		Http.getInstant().sendRequest(context, map, new HttpListener() {
			
			@Override
			public void onHttpSuccess(String result) {
				EventBus.getDefault().post("", "refresh");
				Toast.makeText(context, "删除成功！", Toast.LENGTH_SHORT).show();
				remove(arg1);
				notifyDataSetChanged();
			}
			
			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub
				
			}
		});
	}

   
}
